

/*********************************************************************************************************************************************
* CLASS NAME : BCEntity
* 
* PURPOSE : 
*
* It creates the dx9 sprite and a control interface for a battle city entity.
* All entities in the game (players , enemies , items , explosions and bullets) are derived from this class
* The class has a virtual draw() and update() method which must be implemented in derived classes ! (each entity type has its own method)
*
* Derived From : This is a base class
**********************************************************************************************************************************************/


#ifndef BC_ENTITY_H
#define BC_ENTITY_H

#include "dependancies.h"
#include "BC_Bound.h"
#include "BC_Debugger.h"


enum eEntityType
{
	BC_ENT_PLAYER,				// Player type
	BC_ENT_ENEMY,				// AI Driven entity
	BC_ENT_STAR,				// pick up item  , increases tank firepower and firespeed
	BC_ENT_HELMET,				// pick up item , Sets the player invulnerable for certain time
	BC_ENT_BOMB,				// Kills all the enemies in the scene
	BC_ENT_1UP,					// Adds 1 life for player
	BC_ENT_EAGLEWALL,			// Creates a concrete wall around the eagle for certain time
	BC_ENT_BOAT,				// Makes the player capable of go trough water in the scene
};







class BCEntity
{
	
	public :
		
		virtual ~BCEntity();

		// Sets the position of the entity :
		void setPosition(const BCVector2d& pos);
		
		void setRotation(float rotation){this->rotation = (3.14159265359 / 180.f) * rotation;}

		void setScale(float scale);

		// Sets the name of the entity :
		void setName(const std::string& name);

		// sets the moving speed if the entity :
		void setMoveSpeed(float speed){this->moveSpeed = speed;}
		
		// sets the animation speed of the entity :
		void setAnimationSpeed(float speed);

		// Sets the energy of the entity.
		void setEnergy(float energy);


		// moves the entity left , by its speed
		void moveLeft();

		// moves the entity right , by its speed
		void moveRight();

		// moves the entity up , by its speed
		void moveUp();

		// moves the entity left , by its speed
		void moveDown();

		// Returns the position of the entity :
		BCVector2d getPosition() const;


		// inits the internal data.We need to pass the device pointer and our texture pointer
		static void init(LPDIRECT3DDEVICE9 device , LPDIRECT3DTEXTURE9 texture);
		
		// sets the texture of the entity.
		static void setTexture(LPDIRECT3DTEXTURE9 texture);

		// Draws the Entity :
		virtual void draw();

		// updates the entity by specific deltatime
		virtual bool update(float deltaTime);


		// calculates the animation data for this entity.All entities have their own animate() method
		virtual void animate(float deltaTime);
		

		// sets the frame of this entity.
		void setFrame(int frameSetId);


		// plays the animation from a defined frame set
		void playAnimation(int frameSetId);

		// stops the animation :
		void stopAnimation();

		// creates a new frameset
		void createFrameSet(int frameSetId);

		// Adds a new frame to animation data.The left top right bottom variables are the texture atlas coordinates 
		void addFrame(int frameSetId , int left , int top , int right , int bottom);

		void removeFrame(int frameId);


	protected :


		// Animation data

		struct sFrameSet
		{
			int frameSetId;
			std::vector<RECT> atlasCoordinates;
		};


		BCEntity(const BCVector2d& pos , eEntityType type , float speed , float damage , float animationSpeed , float energy);

		static LPDIRECT3DDEVICE9 dxDevice;
		static LPDIRECT3DTEXTURE9 textureAtlas;
		LPD3DXSPRITE sprite;
		std::string name;
	


		float moveSpeed , animationSpeed ,energy , damage;

		float rotation , scale;

		BCVector2d position , oldPosition;
		
		// list of animation frames
		std::list<sFrameSet> animationFrames;

		// a pointer to our curent frameset . May be NULL if there's no valid framset.
		sFrameSet * currentFrameSet;

		eEntityType entityType;

		// The matrix of the sprite :
		D3DXMATRIX mat;

		// rectangle of the sprite for frame calculation
		RECT rec;

		// true if the animation is playing
		bool animationPlaying;

		float currentFrameTime;
		int currentFrameSetId , frameCounter;


};














#endif












